package com.hnevc.trafficdemotest1.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hnevc.trafficdemotest1.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/3/003.
 */

public class DataAnalysisFragment extends Fragment {
    View view;
    FragmentPagerAdapter fragmentPagerAdapter;
    DataAnalysisViewPageFragment1 dataAnalysisViewPageFragment1;
    DataAnalysisViewPageFragment2 dataAnalysisViewPageFragment2;
    DataAnalysisViewPageFragment3 dataAnalysisViewPageFragment3;
    DataAnalysisViewPageFragment4 dataAnalysisViewPageFragment4;
    DataAnalysisViewPageFragment5 dataAnalysisViewPageFragment5;
    DataAnalysisViewPageFragment6 dataAnalysisViewPageFragment6;
    DataAnalysisViewPageFragment7 dataAnalysisViewPageFragment7;

    List<Fragment> fragmentList = new ArrayList<>();
    ViewPager viewPager;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.data_analysis_fragmemt, container, false);
        dataAnalysisViewPageFragment1 = new DataAnalysisViewPageFragment1();
        dataAnalysisViewPageFragment2 = new DataAnalysisViewPageFragment2();
        dataAnalysisViewPageFragment3 = new DataAnalysisViewPageFragment3();
        dataAnalysisViewPageFragment4 = new DataAnalysisViewPageFragment4();
        dataAnalysisViewPageFragment5 = new DataAnalysisViewPageFragment5();
        dataAnalysisViewPageFragment6 = new DataAnalysisViewPageFragment6();
        dataAnalysisViewPageFragment7 = new DataAnalysisViewPageFragment7();
        fragmentList.add(dataAnalysisViewPageFragment1);
        fragmentList.add(dataAnalysisViewPageFragment2);
        fragmentList.add(dataAnalysisViewPageFragment3);
        fragmentList.add(dataAnalysisViewPageFragment4);
        fragmentList.add(dataAnalysisViewPageFragment5);
        fragmentList.add(dataAnalysisViewPageFragment6);
        fragmentList.add(dataAnalysisViewPageFragment7);

        fragmentPagerAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

        };
        viewPager = (ViewPager) view.findViewById(R.id.data_analysis_viewPage);
        viewPager.setAdapter(fragmentPagerAdapter);
        final ImageView imageView1 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_1);
        final ImageView imageView2 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_2);
        final ImageView imageView3 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_3);
        final ImageView imageView4 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_4);
        final ImageView imageView5 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_5);
        final ImageView imageView6 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_6);
        final ImageView imageView7 = (ImageView) view.findViewById(R.id.data_analysis_viewPage_7);
        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        imageView1.setImageResource(R.drawable.page_indicator_focused);
                        imageView2.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView3.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView4.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView5.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView6.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView7.setImageResource(R.drawable.page_indicator_unfocused);

                        break;
                    case 1:
                        imageView1.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView2.setImageResource(R.drawable.page_indicator_focused);
                        imageView3.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView4.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView5.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView6.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView7.setImageResource(R.drawable.page_indicator_unfocused);
                        break;
                    case 2:
                        imageView1.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView2.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView3.setImageResource(R.drawable.page_indicator_focused);
                        imageView4.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView5.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView6.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView7.setImageResource(R.drawable.page_indicator_unfocused);
                        break;
                    case 3:
                        imageView1.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView2.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView3.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView4.setImageResource(R.drawable.page_indicator_focused);
                        imageView5.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView6.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView7.setImageResource(R.drawable.page_indicator_unfocused);
                        break;
                    case 4:
                        imageView1.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView2.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView3.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView4.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView5.setImageResource(R.drawable.page_indicator_focused);
                        imageView6.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView7.setImageResource(R.drawable.page_indicator_unfocused);
                        break;
                    case 5:
                        imageView1.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView2.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView3.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView4.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView5.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView6.setImageResource(R.drawable.page_indicator_focused);
                        imageView7.setImageResource(R.drawable.page_indicator_unfocused);
                        break;
                    case 6:
                        imageView1.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView2.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView3.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView4.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView5.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView6.setImageResource(R.drawable.page_indicator_unfocused);
                        imageView7.setImageResource(R.drawable.page_indicator_focused);
                        break;
                }
            }
        });
        return view;
    }

    public DataAnalysisFragment() {

    }

}
